package com.micro.client;

import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.*;
import com.micro.request.MealOrderRequest;

import java.util.List;
import java.util.Map;

@FeignClient(name = "train-service", fallback = TrainServiceClientFallback.class)
public interface TrainServiceClient {
    
    @GetMapping("/api/trains/number/{trainNumber}")
    Map<String, Object> getTrainByNumber(@PathVariable("trainNumber") String trainNumber);
    
    @GetMapping("/api/trains/{trainId}")
    Map<String, Object> getTrainById(@PathVariable("trainId") Long trainId);
    
    @PostMapping("/api/seats/purchase")
    Long purchaseTicket(@RequestParam("trainId") Long trainId, 
                       @RequestParam("seatType") Integer seatType, 
                       @RequestParam("quantity") Integer quantity,
                       @RequestParam("travelDate") String travelDate);
    
    @GetMapping("/api/seats/{seatId}")
    Map<String, Object> getSeatById(@PathVariable("seatId") Long seatId);
    
    @GetMapping("/api/stations/{stationId}")
    Map<String, Object> getStationById(@PathVariable("stationId") Long stationId);

    /**
     * 处理火车餐库存
     */
    @PostMapping("/api/meals/inventory/process")
    boolean processMealInventory(@RequestBody List<MealOrderRequest.MealOrderItemRequest> items);
    
    public static class TrainDTO {
        @com.fasterxml.jackson.annotation.JsonProperty("列车ID")
        private Long trainId;
        
        @com.fasterxml.jackson.annotation.JsonProperty("车次")
        private String trainNumber;
        
        @com.fasterxml.jackson.annotation.JsonProperty("始发站ID")
        private Long departureStationId;
        
        @com.fasterxml.jackson.annotation.JsonProperty("终点站ID")
        private Long terminalStationId;
        
        @com.fasterxml.jackson.annotation.JsonProperty("始发时间")
        private String departureTime;
        
        @com.fasterxml.jackson.annotation.JsonProperty("终到时间")
        private String arrivalTime;
        
        // 构造函数
        public TrainDTO() {}
        
        // Getter和Setter方法
        public Long getTrainId() {
            return trainId;
        }
        
        public void setTrainId(Long trainId) {
            this.trainId = trainId;
        }
        
        public String getTrainNumber() {
            return trainNumber;
        }
        
        public void setTrainNumber(String trainNumber) {
            this.trainNumber = trainNumber;
        }
        
        public Long getDepartureStationId() {
            return departureStationId;
        }
        
        public void setDepartureStationId(Long departureStationId) {
            this.departureStationId = departureStationId;
        }
        
        public Long getTerminalStationId() {
            return terminalStationId;
        }
        
        public void setTerminalStationId(Long terminalStationId) {
            this.terminalStationId = terminalStationId;
        }
        
        public String getDepartureTime() {
            return departureTime;
        }
        
        public void setDepartureTime(String departureTime) {
            this.departureTime = departureTime;
        }
        
        public String getArrivalTime() {
            return arrivalTime;
        }
        
        public void setArrivalTime(String arrivalTime) {
            this.arrivalTime = arrivalTime;
        }
    }
    
    public static class StationDTO {
        private Long stationId;
        private String stationName;
        private String city;
        
        // 构造函数
        public StationDTO() {}
        
        // Getter和Setter方法
        public Long getStationId() {
            return stationId;
        }
        
        public void setStationId(Long stationId) {
            this.stationId = stationId;
        }
        
        public String getStationName() {
            return stationName;
        }
        
        public void setStationName(String stationName) {
            this.stationName = stationName;
        }
        
        public String getCity() {
            return city;
        }
        
        public void setCity(String city) {
            this.city = city;
        }
    }
}
